package com.example.springbootshiro.service.base.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.springbootshiro.entity.base.BaseEntity;
import com.example.springbootshiro.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;

/**
 * @Author: lex
 * @Date: 2018/11/14
 */
public class BaseServiceImpl<M extends BaseMapper<T>, T extends BaseEntity> extends ServiceImpl<M, T> implements BaseService<T> {

    @Autowired
    protected BaseMapper<T> baseMapper;

    @Override
    public int logicDeleteById(T t) {
        t.setIsDelete((short) 1);
        return baseMapper.updateById(t);
    }

    @Override
    public T query(T t) {
        return baseMapper.selectOne(new QueryWrapper<>(t));
    }

    @Override
    public List<T> listEntity(T t) {
        return baseMapper.selectList(new QueryWrapper<>(t));
    }

    @Override
    public IPage<T> pageEntity(Integer page,Integer pageSize,T t) {
        return baseMapper.selectPage(new Page<>(page,pageSize),new QueryWrapper<>(t));
    }

}
